﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class ShowDataDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userName"] == null || Session["roleID"] == null)
        {
            Response.Redirect("Login.aspx");
            Response.End();
        }
        if (!Page.IsPostBack)
        {            
            lblBackUrl.Text = Request.UrlReferrer.ToString();
            string DataID = Request.QueryString["DataId"].ToString();
            GetDataMessageAndBind(DataID);
            BindAttachFiles(DataID);
            string userName = Session["userName"].ToString();
            string roleID = Session["roleID"].ToString();
            string LCID = "LC" + DataID;
            Boolean ismyFlow = true;            
            CheckFlow CF = new CheckFlow();
            ismyFlow = CF.CheckIsMyFlow(userName, LCID);           
            if (ismyFlow == false)
            {
                btnCheck.Visible = false;
            }
            else
            {
                btnCheck.Visible = true;
            }
        }

        

    }
    //获取并绑定数据
    protected void GetDataMessageAndBind(string DataID)
    {
        string tabYear = DataID.Substring(2, 4);
        string tabName="DATA"+tabYear;
        string sqlString = "select * From " + tabName + " where DATAID='" + DataID + "'";
        DBOperation DBO=new DBOperation();
        SqlDataReader sdr = DBO.GetDataReader(sqlString);
        //获取流程状态
        string LCStatus = DBO.ExcuteScalar("select STATUS from LC" + tabYear + " where DATAID='" + DataID + "'").ToString();
        if (sdr.Read())
        {
            if (LCStatus == "1")
            {
                btnCheck.Visible = false;
            }
            lblStatus.Text = BasicClass.GetDataStatusNameByStatusID(LCStatus);
            lblDataID.Text = sdr["DATAID"].ToString();
            lblTrueFlowID.Text = "LC" + sdr["DATAID"].ToString();
            lblTitle.Text = sdr["TITLE"].ToString();
            lblSubTitle.Text = sdr["SUBTITLE"].ToString();
            lblSubType.Text = sdr["FLOWSUBTYPEID"].ToString();            
            lblCurrentOperator.Text = DataOperation.GetCurrentOperatorByDataID(sdr["DATAID"].ToString());
            lblWriteDate.Text = Convert.ToDateTime(sdr["WRITEDATE"].ToString()).ToShortDateString();
            lblUpUser.Text =BasicClass.GetTrueNameByUserName(sdr["USERNAME"].ToString());
            lblBrief.Text = sdr["BRIEF"].ToString();
            string FilesPath = sdr["FILESPATH"].ToString();
            string encodeFilePath = Server.UrlEncode(FilesPath);            
            lblFiles.Text = "<img src='images/filePic.gif' /><a href='DownLoad.aspx?filepath=" + encodeFilePath + "' target='blank'>" + FilesPath.Substring(FilesPath.LastIndexOf("\\") + 1) + "</a>";
            
            BasicClass BC = new BasicClass();
            lblDataTypeName.Text = BC.GetFlowTypeNameByShortMark(sdr["FLOWTYPEMARK"].ToString());
        }
        sdr.Close();
    }
    protected void BindAttachFiles(string DataID)
    {
        string lblFilesText = "";
        string fileName = "";
        string filePath = "";
        DataOperation DataO = new DataOperation();
        Hashtable annexFiles =DataO.GetAnnexFiles(DataID);
        for (int i = 0; i < annexFiles.Count; i++)
        {
            if (annexFiles[i].ToString() != "")
            {
                fileName = annexFiles[i].ToString();
                fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
                filePath = annexFiles[i].ToString();
                int item = i + 1;
                filePath = Server.UrlEncode(filePath);
                lblFilesText += item.ToString() + "、<img src='images/filePic.gif' /><a href='DownLoad.aspx?filepath=" + filePath + "' target='blank'>" + fileName + "</a>,&nbsp;&nbsp;&nbsp;&nbsp;";
            }
        }
        lblAnnexFiles.Text = lblFilesText;

    }
    //审核按钮单击事件
    protected void btnCheck_Click(object sender, EventArgs e)
    {
        Response.Redirect("CheckData.aspx?DataId=" + lblDataID.Text);
    }
    protected void btnViewCheckStatus_Click(object sender, EventArgs e)
    {
        string flowId=lblTrueFlowID.Text.ToString();
        string toURL = "FlowStatusBill.aspx?flowId=" + flowId + "";
        Response.Redirect(toURL);
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string refURL = "MessageInfo.aspx";
        Response.Redirect(refURL);
    }    
}
